<h1 class="library_title">Search Results</h1>
<div class="horizontal_line"></div>
<p> for query "<%= @search_text %>" </p>
<% if @results.size > 0 %>
<p class="search_count"> View (
<% @count_links.each do |lim| %>
    <%  if lim == @limit && lim < @res_size%>
        <%= lim.to_s %>   
    <% elsif lim < @res_size %>
        <%= link_to lim.to_s,{:action => "index" , :search => @search_text, :limit => lim }%>
    <% end %>
<% end %>
 <%  if @limit == @res_size %>
       <%= @res_size.to_s %>
 <% else %>
      <%= link_to @res_size.to_s,{:action => "index" , :search => @search_text, :limit => @res_size }%>  
 <% end %>
)</p>
<% end %>
<div class="horizontal_line"></div>
<% counter = @limit %>
<% if @results.size > 0 %>
<%      @results.each_with_index { |e, index| 
            vCountry = e.name
            if index==0 || (@results[index - 1].name != vCountry) %>
                <p class="search_country"><%= vCountry %></p>
                <ul class="search_list"> 
            <% end %>
            <li><%= link_to e.title, :controller =>"ecases",:action=> "show" ,:id=> e[:ecase_id] ? e[:ecase_id] : e[:id] %> </li>
            <% counter -= 1  %>
            <% if !e[:events].nil? && counter > 0
                    e[:events].each  do |e_event| %>
                            <li class="sub"><%= link_to e_event[:event_title], :controller =>"events",:action=> "show" ,:id=> e_event[:id] %> </li>
                             <% counter -= 1 %>   
                             <% 
                                if counter == 0
                                    break
                                end
                              %>
                    <% end %>
            <% end %>
            <% if !@results[index + 1] || (@results[index + 1].name != vCountry) || counter == 0 %>
                 </ul>
            <% end %>
            <% 
            if counter == 0
                break
            end
            %>
    <% } %>         
 <% end %>

